/*
 * @Author: wanfa.bai
 * @Date: 2022-03-12 11:33:47
 * @LastEditors: alan 1499455027@qq.com
 * @LastEditTime: 2025-03-11 21:51:54
 * @Description:
 */

/**
 * @description 单链表结点类
 * @param {*} element
 */
function Node(data) {
    this.data = data;
    this.next = null;
}

/**
 * @description 单链表
 */
function SingleLinkedList() {
    this.head = null; //链表头节点
    this.tail = null; //链表尾节点
}

SingleLinkedList.prototype.add = function (data) {
    let node = new Node(data);
    if (!this.head) {
        this.head = node;
        this.tail = node;
    } else {
        this.tail.next = node; //将原链表尾节点的next指向当前新增节点
        this.tail = node; //更新原链表尾部节点为当前新增节点
    }
};
